export {};
// 类型、约束
type Obj = {
  name: string;
  age: number;
};

type Key = 'name' | 'age';

// 定义函数
const getProp = <T extends Obj, K extends Key>(obj: T, key: K): T[K] => {
  // 返回值
  return obj[key];
};

console.log(getProp({ name: 'Jack', age: 18 }, 'name'));
console.log(getProp({ name: 'Jack', age: 18 }, 'age'));
